function [posextract,flaglevel]=extractlevels(repnames,stanames)
% function [posextract,flaglevel]=extractlevels(repnames,stanames)
% Pass a cell repnames which is a subset of a bigger cell stanames. 
% Names in repnames must equal the name is stanames, except for the possible addition of the string 
% + lev, with a blank space in between, in which case
% the indictor flaglevel will be 1, else 0. 
%
% E.g. stanames={'dY','dC','R','p'} 
%      repnames={'dY lev','R','p' }; 
% will generate posextract=[1 3 4]; 
%               flaglevel= [1 0 0]; 
% AJ Jan 9 2012. 
nr=length(repnames); 
posextract=zeros(nr,1); 
flaglevel =zeros(nr,1); 

for ii=1:nr; 
    name=repnames{ii}; 
    %check=findstr(name,' lev');
    check=regexpi(name,' lev'); 
    if ~isempty(check); 
        posextract(ii)=cellposition(name(1:check),stanames); 
        flaglevel(ii )=1; 
    else 
        posextract(ii)=cellposition(name,stanames); 
    end 
end 
topcell={'Name','Position','Level indic'}; 
botcell=([repnames(:) num2cprec(posextract,1) num2cprec(flaglevel,1)]); 
printcell([topcell;botcell]); 

    
    

